package com.ailink.tx;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

    public UserServiceImpl() {

    }

    private UserRepository userRepository;

    @Autowired
    public void setUserRepository(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

//    @Transactional
    @Override
    public void add(UserEntity entity) {
        userRepository.save(entity);
//        if (true) {
//            throw new RuntimeException();
//        }
        this.add1(entity);
    }

    @Transactional
    @Override
    public void add1(UserEntity entity) {
        userRepository.save(entity);

        if (true) {
            throw new RuntimeException();
        }
    }
}
